﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using lgmkr;

namespace dbcntn
{
    public class ConnectionToDb
    {
        #region Private members

        private MySqlConnection _mySqlConnection;
        private MySqlCommand _mySqlCommand;
        private MySqlDataReader _reader;
        private MySqlDataAdapter _adapter;
        private DataTable fTable;
        private LogMaker aLogMaker;
        private string _priv = "0";


        #endregion

        #region Public Members

        public string ConnectionString { get; set; }

        public DataTable Table { get; set; }

        public ConnectionToDb(string aConnectionstring)
        {
            ConnectionString = aConnectionstring;
        }

        public bool TestConnection()
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return _mySqlConnection.Ping();
        }

        public string Checkuser(string aUserId, string aPassword)
        {
            string id = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            _mySqlCommand = _mySqlConnection.CreateCommand();
            _mySqlCommand.CommandText = "select priv_id from users where Identity_no=" + aUserId + " and password='" +
                                        aPassword + "' ";
            try
            {
                _mySqlConnection.Open();
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    _priv = _reader["priv_id"].ToString();
                }
                _mySqlConnection.Close();

            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }

            return _priv;
        }

        public string SelectUserName(string sId)
        {
            string name = String.Empty, surname = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = "Select name,surname from users where Identity_no=" + sId;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    name = _reader["Name"].ToString();
                    surname = _reader["surname"].ToString();
                }
                _mySqlConnection.Close();

            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return name + "  " + surname;
        }

        public int MaxId(string tableNAme)
        {
            int maxId = 0;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = "Select max(id) from " + tableNAme;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    maxId = Convert.ToInt32(_reader["max(id)"].ToString());
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return maxId;
        }

        public void AddItem(ComboBox aComboBox, string tableName)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlCommand = new MySqlCommand();
                _mySqlCommand.CommandText = "select distinct * from " + tableName;
                var adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                var aTable = new DataTable();
                adapter.Fill(aTable);
                aComboBox.DataSource = aTable;
                aComboBox.DisplayMember = "description";
                aComboBox.ValueMember = "ID";
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + tableName;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message + " " + tableName);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + tableName;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message + " " + tableName);
            }


        }

        public void AddItem(ComboBox aComboBox, string tableName, string foreignkey, int id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlCommand = new MySqlCommand();
                _mySqlCommand.CommandText = "select distinct * from " + tableName + " where " + foreignkey + "=" +
                                            Convert.ToString(id);
                var adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                var aTable = new DataTable();
                adapter.Fill(aTable);
                aComboBox.DataSource = aTable;
                aComboBox.DisplayMember = "description";
                aComboBox.ValueMember = "ID";
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void AddItem(ComboBox aComboBox, string tableName, string tableRow, string foreignkey, int id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlCommand = new MySqlCommand();
                _mySqlCommand.CommandText = "select " + tableRow + " from " + tableName + " where " + foreignkey + "=" +
                                            Convert.ToString(id);
                var adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                var aTable = new DataTable();
                adapter.Fill(aTable);
                aComboBox.DataSource = aTable;
                aComboBox.DisplayMember = "description";
                aComboBox.ValueMember = tableRow;
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }

            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void AddItem(ComboBox aComboBox, string tableName,  string foreignkey1,string foreignkey2, int id1,int id2)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlCommand = new MySqlCommand();
                _mySqlCommand.CommandText = "select distinct * from " + tableName + " where " + foreignkey1 + "=" +
                                            Convert.ToString(id1)+" and "+foreignkey2+"="+id2;
                var adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                var aTable = new DataTable();
                adapter.Fill(aTable);
                aComboBox.DataSource = aTable;
                aComboBox.DisplayMember = "description";
                aComboBox.ValueMember = "ID";
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }

            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void AddItemDBGridView(DataGridView aDataGridView, string query)
        {

            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection = new MySqlConnection(ConnectionString);
                _mySqlCommand = new MySqlCommand {CommandText = query};
                _mySqlConnection.Open();
                _adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                fTable = new DataTable {Locale = CultureInfo.InvariantCulture};
                _adapter.Fill(fTable);
                _mySqlConnection.Close();
                aDataGridView.DataSource = fTable;
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + e.StackTrace;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public DataTable GetDataTable( string query)
        {

            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection = new MySqlConnection(ConnectionString);
                _mySqlCommand = new MySqlCommand { CommandText = query };
                _mySqlConnection.Open();
                _adapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _mySqlConnection);
                fTable = new DataTable { Locale = CultureInfo.InvariantCulture };
                _adapter.Fill(fTable);
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + e.StackTrace;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return fTable;
        }

        public bool CheckDataFromMainTable(string student_id)
        {
            bool result = false;
            string temp = null;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            _mySqlCommand = _mySqlConnection.CreateCommand();
            _mySqlCommand.CommandText = "select ID_student from onmaintable where student_id like('" + student_id + "')";
            try
            {
                _mySqlConnection.Open();
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    temp = _reader[0].ToString();
                }
                _mySqlConnection.Close();
                if (temp != null)
                {
                    result = true;
                }
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public bool CheckDataFromArxiv(string student_id)
        {
            bool result = false;
            string temp = null;
             _mySqlConnection = new MySqlConnection(ConnectionString);
            _mySqlCommand = _mySqlConnection.CreateCommand();
            _mySqlCommand.CommandText = "select max(ID_student) from arsiv where student_id like('"+student_id+"')";
            try
            {
                _mySqlConnection.Open();
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    temp = _reader[0].ToString();
                }
                _mySqlConnection.Close();
                if (temp!="")
                {
                    result = true;
                }
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public bool CheckDataFromArxiv(string student_id,string condition,string val)
        {
            bool result = false;
            string temp = null;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            _mySqlCommand = _mySqlConnection.CreateCommand();
            _mySqlCommand.CommandText = "select max(ID_student) from arsiv where student_id like('" + student_id + "') and "+condition+"="+val;
            try
            {
                _mySqlConnection.Open();
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    temp = _reader[0].ToString();
                }
                _mySqlConnection.Close();
                if (temp != "")
                {
                    result = true;
                }
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public bool CreateBAckUp()
        {
            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = "SQL files|*.sql";
            sf.FileName = "BackUp" + DateTime.Now.ToString("yyyyMMddHHmmss");
            if (sf.ShowDialog() != DialogResult.OK)
                return false;
            MySqlBackup aBackup=new MySqlBackup(ConnectionString);
            aBackup.ExportInfo.FileName = sf.FileName;
            aBackup.ExportInfo.RecordDumpTime = true;
            aBackup.ExportInfo.AddCreateDatabase = true;
            aBackup.ExportInfo.AsynchronousMode = true;
            aBackup.ExportInfo.AutoCloseConnection = true;
            aBackup.ExportInfo.CalculateTotalRowsFromDatabase = true;
            aBackup.ExportInfo.ExportEvents = true;
            aBackup.ExportInfo.ExportFunctions = true;
            aBackup.ExportInfo.ExportRows = true;
            aBackup.ExportInfo.ExportStoredProcedures = true;
            aBackup.ExportInfo.ExportTableStructure = true;
            aBackup.ExportInfo.ExportTriggers = true;
            aBackup.ExportInfo.ExportViews = true;
            aBackup.ExportInfo.ResetAutoIncrement = false;
            aBackup.ExportInfo.MaxSqlLength = (int)10024;
            aBackup.ExportInfo.TableCustomSql = GetTableSql();
            aBackup.ExportInfo.ZipOutputFile = false;
            try
            {
                aBackup.Export();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
            return true;
        }
        Dictionary<string, string>
            GetTableSql()
        {
            Dictionary<string, string> dicTableSql = new Dictionary<string, string>();

            var temp = new MySqlBackup(ConnectionString);
            string[] tables = temp.DatabaseInfo.TableNames;
            foreach (var s in tables)
            {
                string tablename = s;
                string sql = "select * from " + s;
                if (sql == "")
                {
                    sql = string.Format("SELECT * FROM `{0}`;", tablename);
                }
                dicTableSql.Add(tablename, sql);
            }
            if (dicTableSql.Count == 0)
                return null;
            return dicTableSql;
        }
        #endregion

        #region SelectMethods

        public int SelectTable(string[,] tableName)
        {
            int result = 0;
            _mySqlConnection = new MySqlConnection(ConnectionString);

            for (var i = 0; i < 8; i++)
            {
                try
                {
                    _mySqlConnection.Open();
                    string command = "SELECT ball from " + tableName[0, i] + " where id=" + tableName[1, i];
                    _mySqlCommand = _mySqlConnection.CreateCommand();
                    _mySqlCommand.CommandText = command;
                    _reader = _mySqlCommand.ExecuteReader();
                    while (_reader.Read())
                    {
                        result += Int32.Parse(_reader[0].ToString());
                    }
                    _mySqlConnection.Close();
                }
                catch (MySqlException e)
                {
                    aLogMaker = new LogMaker();
                    aLogMaker.Error = e.Message;
                    aLogMaker.PrintLog();
                    MessageBox.Show(e.Message);
                }
                catch (Exception e)
                {
                    aLogMaker = new LogMaker();
                    aLogMaker.Error = e.Message;
                    aLogMaker.PrintLog();
                    MessageBox.Show(e.Message);
                }

            }
            return result;
        }

        public string SelectTable(string tableName, int id)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT name_nation from " + tableName + " where id=" + Convert.ToString(id);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader["name_nation"].ToString();
                }
                _mySqlConnection.Close();

            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + e.StackTrace;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public List<string>[] SelectTable(string tableName)
        {
            int j = 0;
            List<string>[] result = new List<string>[] {};
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT * from " + tableName;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                result = new List<string>[_reader.FieldCount];
                for (int i = 0; i < _reader.FieldCount; i++)
                {
                    result[i] = new List<string>();
                }
                while (_reader.Read())
                {
                    j++;
                    for (int i = 0; i < _reader.FieldCount; i++)
                    {
                        result[j].Add(_reader[i].ToString());
                    }
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + e.StackTrace;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public List<string> SelectTable(string tableName, string condition, string val)
        {

            List<string> result = null;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT * from " + tableName + " where " + condition + "='" + val + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                result = new List<string>();
                while (_reader.Read())
                {
                    for (int i = 0; i < _reader.FieldCount; i++)
                    {
                        result.Add(_reader[i].ToString());
                    }
                }
                _mySqlConnection.Close();
                return result;
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker {Error = e.Message + " " + e.StackTrace};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker {Error = e.Message};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }
        public List<string> SelectTable(string tableName, string[] columnname, string condition, string val)
        {

            List<string> result = null;
            string command = "SELECT  ";
            _mySqlConnection = new MySqlConnection(ConnectionString);
            for (int i = 0; i < columnname.Count() - 1; i++)
            {
                command += columnname[i] + ",";
            }
            command += columnname[columnname.Count() - 1] + " from " + tableName + " where " + condition + "='" + val +
                       "'";
            MessageBox.Show(command);
            // +tableName + " where " + condition + "='" + val + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                result = new List<string>();
                while (_reader.Read())
                {
                    for (int i = 0; i < columnname.Length; i++)
                    {
                        result.Add(_reader[columnname[i]].ToString());
                    }
                }
                _mySqlConnection.Close();
                return result;
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker {Error = e.Message + " " + e.StackTrace};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker {Error = e.Message};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }
        public string SelectTable(string tableName, string tableRow, int id)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT " + tableRow + " from " + tableName + " where id=" + Convert.ToString(id);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[tableRow].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }
        public List<string> SelectTable(string tableName, string tableRow1, string tableRow2, int id)
        {
            var result = new List<string>();
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT " + tableRow2 + " from " + tableName + " where " + tableRow1 + "=" +
                             Convert.ToString(id);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result.Add(_reader[tableRow2].ToString());
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }
        public string SelectTable(string tableName, string tableRow1, string tableRow2, string value2)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "SELECT " + tableRow2 + " from " + tableName + " where " + tableRow1 + "='" + value2 + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[tableRow2].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length != 0 ? result : "";

        }

        public List<string> SelectStudentId()
        {
            var result = new List<string>();
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select student_id from onmaintable where cource_id<>8 and cource_id<>7 ";
           // string command = "select student_id from onmaintable where id_student<30 ";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result.Add(_reader[0].ToString());
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker { Error = e.Message };
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public List<string> SelectField(string table, string field)
        {
            var result = new List<string>();
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + field + " from " + table;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result.Add(_reader[0].ToString());
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker {Error = e.Message};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }
        public List<string> SelectField(string table, string field,string condition,int val)
        {
            var result = new List<string>();
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + field + " from " + table +" where "+condition+"<>"+val;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result.Add(_reader[0].ToString());
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker {Error = e.Message};
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public string SelectField(string table, string field, string function)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + function + "(" + field + ") from " + table;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }
        public string SelectField(string table, string field, string function,string condition,int value)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + function + "(" + field + ") from " + table+" where "+condition+" ="+value;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }
        public string SelectField(string query)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = query;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }

            return result.Length > 0 ? result : "0";
        }

        public string SelectId(string val)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select id from room where description ='" + val + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }

        public string SelectField(string table, string field, string condition, string val)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + field + " from " + table + " where " + condition + "=" + val+"";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                //MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                //MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }

        public string SelectField(string table, string field, string condition1, string val1, string condition2,
                                  string val2)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select " + field + " from " + table + " where " + condition1 + "=" + val1 + " and " +
                             condition2 + "=" + val2;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }


        public string SelectTableCeza(string studentId)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select sum(b.ball) from joinceza a,ceza b where a.ceza_id=b.id and a.student_id='" +
                             studentId + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result;
        }

        public string SelectOrtalama(string studentId)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select GOrt from EOgrOrtalamaReplYurt where  numara='" + studentId + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }

        

        #endregion

        #region InsertMethods


        public void InsertIntoTable(string tableName, string[] tableRow, params string[] values)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " ("; // +tableRow + ") values('" + values + "')";
            for (int i = 0; i < tableRow.Count() - 1; i++)
            {
                command += tableRow[i] + ",";
            }
            command += tableRow[tableRow.Count() - 1] + ") values('";
            for (int i = 0; i < values.Count() - 1; i++)
            {
                command += values[i] + "','";
            }
            command += values[tableRow.Count() - 1] + "')";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoMaddeBend(string maddeno,string maddebend, string maddetext)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into maddebend(maddeno_id,description,maddetext) values("+maddeno+",'"+maddebend+"','" + maddetext + "')";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTable(string tableName, string tableRow, string values)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " (" + tableRow + ") values('" + values + "')";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTable(string tableName, string tableRow, int values)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " (" + tableRow + ") values(" + Convert.ToString(values) + ")";

            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTable(string tableName, string tableRow1, string tableRow2, int values1, int values2)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " (" + tableRow1 + "," + tableRow2 + ") values(" +
                             Convert.ToString(values1) + "," + Convert.ToString(values2) + ")";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTable(string tableName, string tableRow1, string tableRow2, int values1, string values2)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " (" + tableRow1 + "," + tableRow2 + ") values(" +
                             Convert.ToString(values1) + ",'" + values2 + "')";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }
        public void InsertIntoTable(string tableName, string tableRow1, string tableRow2,string tableRow3, int values1, string values2,int values3)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into " + tableName + " (" + tableRow1 + "," + tableRow2 + ","+tableRow3+") values(" +
                             Convert.ToString(values1) + ",'" + values2 + "',"+values3+")";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoMainTable(List<string> item)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command =
                "INSERT INTO onmaintable " +
                "(no,ceza,donem,student_id,Name, Pol_id, birth_date,birth_place, Home_telephone, Home_address, country_id, nation_id, Passport, Handicap_id, " +
                //13
                " Cource_id, Bolum_id, oratalama, place_id, Dad_name, Dad_surname, Dad_profession, Dad_workaddress, Dad_workphone, Dad_income, Valute_idd, " +
                //11
                "Dad_handicap_id, Dad_health_id, Mom_name, Mom_surname, Mom_profession, Mom_workaddress, mom_workphone, Mom_income, Valute_idm, Mom_handicap_id, " +
                //10
                "Mom_health_id, Parent_state, StudyFamilyCount,regdate,ball,res,odul_aciklama,odul_id)" + //4
                " select inc("+item[3]+"),"+item[40]+",'" + item[0] + "','" + item[1] + "','" + item[2] + "'," + item[3] + ",'" +
                item[4] + "','" + item[5] + "','" + item[6] + "','" + item[7] + "'," +
                "" + item[8] + "," + item[9] + ",'" + item[10] + "'," + item[11] + "," + item[12] + "," + item[13] +
                "," + item[14] + "," + item[15] + ",'" + item[16] + "'," +
                "'" + item[17] + "'," + item[18] + ",'" + item[19] + "','" + item[20] + "','" + item[21] + "'," +
                item[22] + "," + item[23] + "," + item[24] + ",'" + item[25] + "','" + item[26] + "'," +
                "" + item[27] + ",'" + item[28] + "','" + item[29] + "','" + item[30] + "'," + item[31] + "," + item[32] +
                "," + item[33] + "," + item[34] + "," + item[35] + ",'" + item[37] + "'," + item[36] + ","+item[39]+",'"+item[41]+"',"+item[42];
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoKMainTable(List<string> item)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command =
                "INSERT INTO kmaintable " +
                "(no,donem,student_id,Name, Pol_id, birth_date,birth_place, Home_telephone, Home_address, country_id, nation_id, Passport, Handicap_id, " +
                //13
                " Cource_id, Bolum_id, oratalama, place_id, Dad_name, Dad_surname, Dad_profession, Dad_workaddress, Dad_workphone, Dad_income, Valute_idd, " +
                //11
                "Dad_handicap_id, Dad_health_id, Mom_name, Mom_surname, Mom_profession, Mom_workaddress, mom_workphone, Mom_income, Valute_idm, Mom_handicap_id, " +
                //10
                "Mom_health_id, Parent_state, StudyFamilyCount,regdate,kronik_hasta,kronik_turu,alerji,alerji_turu,bloodgrup_id,bed_id,enter_date,exit_date,sigara,exit_reason,health_report,ball)" +
                //17
                "select  inck(" + item[3] + "),'" + item[0] + "','" + item[1] + "','" + item[2] + "'," +
                item[3] + ",'" + item[4] + "','" + item[5] + "','" + item[6] + "','" + item[7] + "'," +
                "" + item[8] + "," + item[9] + ",'" + item[10] + "'," + item[11] + "," + item[12] + "," + item[13] +
                "," + item[14] + "," + item[15] + ",'" + item[16] + "'," +
                "'" + item[17] + "'," + item[18] + ",'" + item[19] + "','" + item[20] + "','" + item[21] + "'," +
                item[22] + "," + item[23] + "," + item[24] + ",'" + item[25] + "','" + item[26] + "'," +
                "" + item[27] + ",'" + item[28] + "','" + item[29] + "','" + item[30] + "'," + item[31] + "," + item[32] +
                "," + item[33] + "," + item[34] + "," + item[35] + ",'" + item[36] + "'," + item[37] + ",'" + item[38] +
                "'," + item[39] + ",'" + item[40] + "'," + item[41] + "," + item[42] + ",'" + item[43] + "','" +
                item[44] + "'," + item[45] + ",'" + item[46] + "','" + item[47] + "'," + item[48] ;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTableDisiplin(string studentId,string maddeno,string maddebend,string maddetext,string aciklama, string cezaId,string date)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into disiplin(student_id,maddeno,maddebend,maddetext,description,ceza,date_reg) values('" + studentId + "','"+maddeno+"','"+maddebend+"','"+maddetext+"','"+aciklama+"'," + cezaId + ",'"+date+"')";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoKMainTable(string studentId)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command =
                "INSERT INTO kmaintable " +
                "( donem, student_id, Name, Surname, Pol_id, birth_date, birth_place, Home_telephone, Home_address, country_id, nation_id, Passport, Handicap_id, Cource_id, Bolum_id, oratalama, place_id, Dad_name, Dad_surname, Dad_profession, Dad_workaddress, Dad_workphone, Dad_income, Valute_idd, Dad_handicap_id, Dad_health_id, Mom_name, Mom_surname, Mom_profession, Mom_workaddress, mom_workphone, Mom_income, Valute_idm, Mom_handicap_id, Mom_health_id, Parent_state, StudyFamilyCount, regdate, ball) " +
                "SELECT  donem, student_id, Name, Surname, Pol_id, birth_date, birth_place, Home_telephone, Home_address, country_id, nation_id, Passport, Handicap_id, Cource_id, Bolum_id, oratalama, place_id, Dad_name, Dad_surname, Dad_profession, Dad_workaddress, Dad_workphone, Dad_income, Valute_idd, Dad_handicap_id, Dad_health_id, Mom_name, Mom_surname, Mom_profession, Mom_workaddress, mom_workphone, Mom_income, Valute_idm, Mom_handicap_id, Mom_health_id, Parent_state, StudyFamilyCount, regdate, ball FROM onmaintable " +
                "WHERE student_id='" + studentId + ";";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTableOrtalam(string min, string max, string ball)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into puanortalama (min_value,max_value,ball) values(" + min + "," + max + "," +
                             ball + ")";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void InsertIntoTableUser(string idno, string name, string susrname, string password, string privId)
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "insert into users(identity_no,name,surname,password,priv_id) values(" + idno + ",'" + name +
                             "','" + susrname + "','" + password + "'," + privId + ")";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        #endregion

        #region UpdateMethods

        public void UpdateOrtalama()
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update onmaintable a,EOgrOrtalamaReplYurt b set a.oratalama=b.GOrt where a.student_id=b.numara";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTableMaddeBend(string maddeno, string maddebend, string maddetext, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update maddebend set maddeno_id=" + maddeno + ",description='"+maddebend+"',maddetext='"+maddetext+"' where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTable(string tableName, string tableRow, string values, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update " + tableName + " set " + tableRow + "='" + values + "' where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateUserTable(int values, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update users set online=" + Convert.ToString(values) + " where Identity_no=" +id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTable(string tableName, string tableRow, int values, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update " + tableName + " set " + tableRow + "=" + Convert.ToString(values) + " where id=" +
                             id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTable(string tableName, string tableRow1, string tableRow2, string values1, string values2,
                                string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update " + tableName + " set " + tableRow1 + "=" + values1 + "," + tableRow2 + "='" +
                             values2 + "' where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateRoom(string description, int room, int pol,string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update room set description='" + description + "',yurt_id=" +room + ",pol_id=" + pol + " where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTable(string tableName, string tableRow1, string tableRow2,string tableRow3, string values1, int values2,int values3,
                                string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update " + tableName + " set " + tableRow1 + "=" + values1 + "," + tableRow2 + "=" +
                             values2 + ","+tableRow3+"="+values3+" where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTableOrtalama(string min, string max, string ball, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update puanortalama set min_value=" + min + ",max_value=" + max + ",ball=" + ball +
                             " where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTableUser(string idno, string name, string surname, string password, string forkey, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update users set identity_no=" + idno + ",name='" + name + "',surname='" + surname +
                             "',password='" + password + "',priv_id=" + forkey + " where id=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateTableCeza(string studentId,string maddeno,string maddebend,string maddetext,string aciklama, string ceza, string date, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update disiplin set student_id='" + studentId + "',maddeno='"+maddeno+"',maddebend='"+maddebend+"',maddetext='"+maddetext+"',description='"+aciklama+"',ceza_id=" + ceza + ",date='" + date +
                             "' where id=" + id;
            MessageBox.Show(command);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateKMainTable(string tableRow, int values, string student_id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update kmaintable set " + tableRow + "=" + Convert.ToString(values) +
                             " where student_id='" + student_id + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateKMainTable(string tablerow, string value, string condition, string convalue)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update kmaintable set " + tablerow + "=" + value + " where " + condition + "='" + convalue +
                             "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateKMainTable(List<string> item, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command =
                "UPDATE kmaintable SET donem = '" + item[0] + "',student_id = '" + item[1] + "',Name = '" + item[2] +"',Pol_id = " + item[3] + ",birth_date = '" + item[4] + "',birth_place = '" + item[5] + "',Home_telephone = '" + item[6] +
                "',Home_address = '" + item[7] + "',country_id = " + item[8] + ",nation_id = " + item[9] + ",Passport = '" + item[10] + "',Handicap_id = " + item[11] + ",Cource_id = " + item[12] + ",Bolum_id = " +
                item[13] + ",oratalama = " + item[14] + ",place_id = " + item[15] + ",Dad_name = '" + item[16] + "'," +
                "Dad_surname = '" + item[17] + "',Dad_profession = " + item[18] + ",Dad_workaddress = '" + item[19] +
                "',Dad_workphone = '" + item[20] + "',Dad_income = " + item[21] + "," +
                "Valute_idd = " + item[22] + ",Dad_handicap_id =" + item[23] + ",Dad_health_id = " + item[24] +
                ",Mom_name = '" + item[25] + "',Mom_surname = '" + item[26] + "',Mom_profession = " + item[27] + "," +
                "Mom_workaddress = '" + item[28] + "',mom_workphone = '" + item[29] + "',Mom_income = " + item[30] +
                ",Valute_idm = " + item[31] + ",Mom_handicap_id = " + item[32] + ",Mom_health_id = " + item[33] + "," +
                "Parent_state = " + item[34] + ",StudyFamilyCount = " + item[35] + ",kronik_hasta = " + item[37] +
                ",kronik_turu = '" + item[38] + "',alerji = " + item[39] + "," +
                "alerji_turu = '" + item[40] + "',bloodgrup_id = " + item[41] + ",bed_id = " + item[42] +
                ",enter_date = '" + item[43] + "',exit_date = '" + item[44] + "'," +
                "Sigara = " + item[45] + ",exit_reason = '" + item[46] + "',health_report = '" + item[47] + "',kkayit="+item[48]+" where id_student=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateMainTable(string tableRow, int values, string student_id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update onmaintable set " + tableRow + "=" + Convert.ToString(values) +
                             " where student_id='" + student_id + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateMainTable(List<string> item, string id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "UPDATE onmaintable SET ceza="+item[40]+",donem = '" + item[0] + "',student_id = '" + item[1] + "',Name = '" +
                             item[2] + "',Pol_id = " + item[3] + ",birth_date = '" + item[4] +
                             "',birth_place = '" + item[5] + "',Home_telephone = '" + item[6] + "',Home_address = '" +
                             item[7] + "',country_id = " + item[8] + ",nation_id = " + item[9] + ",Passport = '" +
                             item[10] + "',Handicap_id = " + item[11] + "," +
                             "Cource_id = " + item[12] + ",Bolum_id = " + item[13] + ",oratalama = " + item[14] +
                             ",place_id = " + item[15] + ",Dad_name = '" + item[16] + "',Dad_surname = '" + item[17] +
                             "',Dad_profession = " + item[18] + ",Dad_workaddress = '" + item[19] + "'," +
                             "Dad_workphone = '" + item[20] + "',Dad_income = " + item[21] + ",Valute_idd = " + item[22] +
                             ",Dad_handicap_id = " + item[23] + ",Dad_health_id = " + item[24] + ",Mom_name = '" +
                             item[25] + "',Mom_surname = '" + item[26] + "'," +
                             "Mom_profession = " + item[27] + ",Mom_workaddress = '" + item[28] + "',mom_workphone = '" +
                             item[29] + "',Mom_income = " + item[30] + ",Valute_idm = " + item[31] +
                             ",Mom_handicap_id = " + item[32] + ",Mom_health_id = " + item[33] + "," +
                             "Parent_state = " + item[34] + ",StudyFamilyCount = " + item[35] + ",ball = " + item[36] +",res="+item[39]+",odul_id="+item[42]+",odul_aciklama='"+item[41]+
                             "' where ID_student=" + id;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void UpdateMainTable(string tablerow, string value, string condition, string convalue)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update onmaintable set " + tablerow + "=" + value + " where " + condition + "='" +
                             convalue +
                             "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        //Test Code

        #endregion

        #region DeleteMethods

        public void DeleteTable(string tablename)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "delete from " + tablename;
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void DeleteTable(string tablename, string condition, string val)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "delete from " + tablename + " where " + condition + "='" + val + "'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void DeleteTable(string tablename, string condition, int val)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "delete from " + tablename + " where " + condition + "=" + Convert.ToString(val);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }



        }
        #endregion

        #region Report

        public DataTable GetDataSources(DataSet aSet, string tablename, string query)
        {
            aSet.Clear();
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = query;
                _adapter = new MySqlDataAdapter(_mySqlCommand);
                _adapter.Fill(aSet, tablename);
                _mySqlConnection.Close();
                fTable = aSet.Tables[tablename];
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                fTable = null;
                MessageBox.Show(e.Message);
            }
            catch (ConstraintException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                fTable = null;
                MessageBox.Show(e.Message);
            }
            return fTable;
        }

        #endregion 

        #region Stored procedures

        public void Call(string query)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = query;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }

        public void Call(string query,string student_id)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = query;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + student_id;
                aLogMaker.PrintLog();
                //MessageBox.Show(e.Message+" "+student_id);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message + " " + student_id;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message + " " + student_id);
            }
        }

        #endregion

        #region 2014Added

        public string SelectDate()
        {
            var result = String.Empty;
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "select a.desc from year a where a.id=(select min(id) from year where flag=0)";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _reader = _mySqlCommand.ExecuteReader();
                while (_reader.Read())
                {
                    result = _reader[0].ToString();
                }
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            return result.Length > 0 ? result : "0";
        }

        public void UpdateDate(String desc)
        {
            _mySqlConnection = new MySqlConnection(ConnectionString);
            string command = "update year a set a.flag=1 where a.desc='"+desc+"'";
            try
            {
                _mySqlConnection.Open();
                _mySqlCommand = _mySqlConnection.CreateCommand();
                _mySqlCommand.CommandText = command;
                _mySqlCommand.ExecuteNonQuery();
                _mySqlConnection.Close();
            }
            catch (MySqlException e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                aLogMaker = new LogMaker();
                aLogMaker.Error = e.Message;
                aLogMaker.PrintLog();
                MessageBox.Show(e.Message);
            }
        }


        #endregion
    }
}